package generator.statements;

import generator.addons.SimpleDataGenerator;
import generator.collections.CustomerTable;
import java.util.Random;

/**
 * Customer SQL record mapper.
 * 
 * @author Necro
 * @author Marek Snopkowski <snpy@snpy.info>
 * @version 12.04.2008
 */
public class Customer extends Statement
{
    private int customerID;
    
    private String name;
    private String address;
    private String nip;
    private int isCompany;
    private String phone;

    public Customer(String Name, String Address, String Nip, int isCompany, String Phone)
    {    
        this.customerID = CustomerTable.autoincrement();
        this.name       = Name;
        this.address    = Address;
        this.nip        = Nip;
        this.isCompany  = isCompany;
        this.phone      = Phone;
    }
    
    public Object[] getFieldsValueCollection()
    {
        return new Object[]{ customerID, name, address, nip, isCompany, phone };
    }
    
    public String getFieldsNameSet()
    {
        return "[customer_id], [name], [address], [nip], " +
                "[is_company], [phone]";
    }
    
    public String getName()
    {
        return name;
    }
    
    public String getPhone()
    {
        return phone;
    }
    
    public String getNip()
    {
        return nip;
    }
    
    @Override
    public int getId()
    {
        return customerID;
    }
    
    public static Customer getRand()
    {
        Random rand = new Random();
        String name;
        
        String address = SimpleDataGenerator.getAddress();
        int isCompany  = 0;
        String phone   = SimpleDataGenerator.getPhone();
        String Nip     = null;
        int tmp = rand.nextInt(100);
        if (tmp < 10)
        {
            isCompany = 1;
            name      = SimpleDataGenerator.getCompanyName();
            Nip       = SimpleDataGenerator.getNIP();
        }
        else
        {
            name = SimpleDataGenerator.getName();
        }
        
        return new Customer(name, address, Nip, isCompany, phone);
    }
    
     @Override
    public String getTableName()
    {
        return "customer";
    }
}
